﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using AppNet.Service;
using System.Web.Hosting;

namespace AppNet
{
    public class LanguageConfig
    {
        public static List<CultureInfor> Cultures = new List<CultureInfor>();

        public static void RegisLanguageSupport()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(HostingEnvironment.MapPath("~/LanguageConfig.xml"));
            XmlElement languages = doc.DocumentElement;
            foreach (XmlNode node in languages.ChildNodes)
            {
                string culture = node.Attributes["culture"].Value;
                string name = node.Attributes["name"].Value;
                Cultures.Add(new CultureInfor(culture, name));
            }
        }

        /// <summary>
        /// Check Language Support.
        /// </summary>
        /// <param name="culture">Language</param>
        /// <returns>Is Support.</returns>
        public static bool CheckLanguageSupport(string culture) 
        {
            string c = culture.ToLower();
            foreach(var cul in Cultures)
                if(c.Equals(cul.Culture))
                    return true;
            return false;
        }
    }
}